package com.screwdriver.jso.processor.generator;

import com.screwdriver.jso.client.converter.EnumConverter;
import com.screwdriver.jso.processor.utils.TypeResolver;

/**
 * Created by IntelliJ IDEA.
 * User: jan kowalski
 * Date: 27.08.11
 * Time: 20:54
 * To change this template use File | Settings | File Templates.
 */
public class EnumGenerator extends ReferenceGenerator{


    public String setter(String fromVariableName, TypeResolver propertyType) {
        if (propertyType.isArray()) {
            return String.format("(%2$s!=null ? @%1$s::toJsoValue([Ljava/lang/Enum;)(%2$s):null) ",
                    EnumConverter.class.getCanonicalName(), fromVariableName);
        } else {
            return String.format("(%2$s!=null ? @%1$s::toJsoValue(Ljava/lang/Enum;)(%2$s):null) ",
                    EnumConverter.class.getCanonicalName(), fromVariableName);
        }
    }


    public String getter(String fromVariableName, TypeResolver propertyType) {
        if (propertyType.isArray()) {
            return String.format("(%2$s!=null ? @%1$s::toJavaValue(Lcom/google/gwt/core/client/JsArrayString;Ljava/lang/Class;)(%2$s, @%3$s::class) : null)",
                    EnumConverter.class.getCanonicalName(), fromVariableName, propertyType.getDeclaredType().getDeclaration().getQualifiedName());
        } else {
            return String.format("(%2$s!=null ? @%1$s::toJavaValue(Ljava/lang/String;Ljava/lang/Class;)(%2$s, @%3$s::class) : null)",
                    EnumConverter.class.getCanonicalName(), fromVariableName, propertyType.getDeclaredType().getDeclaration().getQualifiedName());
        }
    }


}
